#include "widget.h"
#include "ui_widget.h"
#include<QPushButton>
#include<QDebug>
#include<QIcon>
#include<QPixmap>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QIcon icon(":/up.png");
    ui->pushButton_up->setIcon(icon);//给按钮设置图标

    QIcon icon1(":/down.png");
    ui->pushButton_down->setIcon(icon1);

    QIcon icon2(":/left.png");
    ui->pushButton_left->setIcon(icon2);

    QIcon icon3(":/right.png");
    ui->pushButton_right->setIcon(icon3);


    ui->pushButton_up->setShortcut(QKeySequence(Qt::Key_W+Qt::CTRL));//给按钮设置快捷键
    ui->pushButton_down->setShortcut(QKeySequence("s"));
    ui->pushButton_left->setShortcut(QKeySequence(Qt::Key_A));
    ui->pushButton_right->setShortcut(QKeySequence(Qt::Key_D));

    QIcon ico(":/up.png");
    this->setWindowIcon(ico);//设置窗口图标

    QPixmap pix(":/up.png");
    pix =pix.scaled(64,64);//设置尺寸
    QCursor cur(pix,2,2);//设置鼠标样式
    this->setCursor(cur);


    ui->pushButton_up->setAutoRepeat(true);
    ui->pushButton_down->setAutoRepeat(true);
    ui->pushButton_left->setAutoRepeat(true);
    ui->pushButton_right->setAutoRepeat(true);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    QRect ret =  ui->textEdit->geometry();
    ui->textEdit->setGeometry(ret.x(),ret.y()-5,ret.width(),ret.height());
    qDebug()<<"up";
}

void Widget::on_pushButton_right_clicked()
{
    QRect ret = ui->textEdit->geometry();
    ui->textEdit->setGeometry(ret.x()+5,ret.y(),ret.width(),ret.height());//获取坐标
      qDebug()<<"right";
}

void Widget::on_pushButton_left_clicked()
{
     QRect ret = ui->textEdit->geometry();
     ui->textEdit->setGeometry(ret.x()-5,ret.y(),ret.width(),ret.height());
      qDebug()<<"left";
}

void Widget::on_pushButton_down_clicked()
{
    QRect ret = ui->textEdit->geometry();
    ui->textEdit->setGeometry(ret.x(),ret.y()+5,ret.width(),ret.height());
      qDebug()<<"down";
}
